﻿<!-- https://blogs.msdn.microsoft.com/pigscanfly/2010/03/28/wpf-styling-the-expander-control/ -->
<!-- This resource dictionary is used by the MainWindow. -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >

    <!-- Main Expander Header Brushes -->
    <SolidColorBrush x:Key="MainExpanderHeaderBackgroundBrush" Color="#FF3771C1"/>
    <SolidColorBrush x:Key="MainExpanderHeaderBorderBrush" Color="Black"/>

    <!-- Main Expander Content Brushes -->
    <SolidColorBrush x:Key="MainExpanderContentBorderBrush" Color="Black" />

    <!-- Main Expander Control Brushes (affect the whole control, not just header or content -->
    <SolidColorBrush x:Key="MainExpanderControlNormalForegroundBrush" Color="White" />
    <SolidColorBrush x:Key="MainExpanderControlDisabledForegroundBrush" Color="DarkGray" />
    <SolidColorBrush x:Key="MainExpanderControlDisabledBackgroundBrush" Color="LightGray" />
    <SolidColorBrush x:Key="MainExpanderControlDisabledBorderBrush" Color="LightGray" />

    <!-- Main Expander Toggle Button Brushes -->
    <SolidColorBrush x:Key="ExpanderToggleButtonBackgroundBrush" Color="White" />
    <SolidColorBrush x:Key="ExpanderToggleButtonMouseOverFillBrush" Color="Green" />
    <SolidColorBrush x:Key="ExpanderToggleButtonPressedFillBrush" Color="Yellow" />

    <!-- Expander Toggle Button Template -->
    <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">

        <!-- Note, the chevron toggle button gets its forground color from the templated parent.
             The parent must set this to a valid color when it is disabled. -->

        <!--<Path 
			Name="Chevron"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Data="M 0 0 L 10 10 L 20 0 Z"
            Fill="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}"
            />

        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="Chevron" Property="Data" Value="M 0 10 L 10 0 L 20 10 Z" />
            </Trigger>
            <Trigger Property="ToggleButton.IsMouseOver" Value="true">
                <Setter TargetName="Chevron" Property="Fill" Value="{StaticResource ExpanderToggleButtonMouseOverFillBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="Chevron" Property="Fill" Value="{StaticResource ExpanderToggleButtonPressedFillBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>-->
        <TextBlock Text="&#x25BA;"></TextBlock>
    </ControlTemplate>

    <Style x:Key="MainViewExpander" TargetType="Expander">
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Name="ContentRow" Height="0"/>
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" Name="HeaderBorder" BorderThickness="0" CornerRadius="0,0,0,0" Background="#dddddd">
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="12" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <ContentPresenter 
                                        Grid.Column="1"
                                        Margin="4" 
                                        ContentSource="Header" 
                                        RecognizesAccessKey="True" 
                                        />
                                <ToggleButton 
                                        Grid.Column="0"
                                        Margin="4"
                                        IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                        OverridesDefaultStyle="True" 
                                        Template="{StaticResource ExpanderToggleButton}" 
                                        Background="{StaticResource ExpanderToggleButtonBackgroundBrush}" 
                                        />
                            </Grid>
                        </Border>

                        <Border Grid.Row="1" Name="ContentBorder"  BorderThickness="0" CornerRadius="0,0,0,0">
                            <ContentPresenter Margin="4" />
                        </Border>
                    </Grid>

                    <!-- Triggers for the entire Expander Control -->
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsExpanded" Value="True">
                            <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content, Path=DesiredHeight}" />
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{StaticResource MainExpanderControlDisabledForegroundBrush}"/>
                            <Setter TargetName="HeaderBorder" Property="Background" Value="{StaticResource MainExpanderControlDisabledBackgroundBrush}" />
                            <Setter TargetName="HeaderBorder" Property="BorderBrush" Value="{StaticResource MainExpanderControlDisabledBorderBrush}" />
                            <Setter TargetName="ContentBorder" Property="BorderBrush" Value="{StaticResource MainExpanderControlDisabledBorderBrush}" />
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding}" FontWeight="DemiBold" />
                </DataTemplate>
            </Setter.Value>
        </Setter>

    </Style>

    <!--<Style x:Key="MainViewExpanderCommands" 
           BasedOn="{StaticResource MainViewExpander}"  
           TargetType="Expander"
           >
        <Setter Property="FontSize" Value="20" />
        <Setter Property="FontWeight" Value="Bold" />
    </Style>-->

</ResourceDictionary>